from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Chrome()
driver.get("https://www.baidu.com/")
# driver.maximize_window()
driver.implicitly_wait(15)

# 定位到搜索框
search = driver.find_element(By.CLASS_NAME,"s_ipt")
search.clear()
search.send_keys("selenium")
driver.find_elements(By.CLASS_NAME,"bg")[1].click()


# 下拉滚动条
win1 = "window.scrollBy(0,800)"  # Y轴向下800像素
win2 = "window.scrollBy(0,-300)"   # Y轴向上300像素
win3 = 'window.scrollBy(500,0)' # X轴向右500像素
win4 = 'window.scrollBy(-500,0)' # X轴向左500像素

# 执行js 滚动条向下
sleep(2)
driver.execute_script(win1)

# 执行js 滚动条向上
sleep(3)
driver.execute_script(win2)

# 执行js 滚动条向右
sleep(3)
driver.execute_script(win3)

# 执行js 滚动条向左
sleep(3)
driver.execute_script(win4)
